package ch.ethz.fcl.metrobuzz.render.techniques.vbo;

import java.nio.FloatBuffer;

import org.lwjgl.opengl.GL11;
import org.lwjgl.opengl.GL15;

public class ArrayBufferObject {
	int id;
	int size;

	public ArrayBufferObject() {
		id = GL15.glGenBuffers();
	}

	public void dispose() {
		GL15.glDeleteBuffers(id);
	}

	public void load(FloatBuffer buffer) {
		bind();
		size = buffer.position();
		buffer.position(0);
		GL15.glBufferData(GL15.GL_ARRAY_BUFFER, buffer, GL15.GL_STATIC_DRAW);
	}

	public void bind() {
		GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, id);
	}

	public int size() {
		return size;
	}

	public void draw(int mode) {
		bind();
		GL11.glVertexPointer(3, GL11.GL_FLOAT, 0, 0);
		GL11.glEnableClientState(GL11.GL_VERTEX_ARRAY);
		GL11.glDrawArrays(mode, 0, size / 3);
		GL11.glDisableClientState(GL11.GL_VERTEX_ARRAY);
	}
}
